package com.cwl.es.config;

import lombok.Getter;
import lombok.Setter;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: cwl_es
 * @description: ES配置文件
 * @author: ChenWenLong
 * @create: 2019-11-05 17:12
 **/
@Configuration
@ConfigurationProperties(prefix = "elasticsearch")
@Getter
@Setter
public class EsConfig {

    private String host;
    private Integer port;

    @Bean(destroyMethod = "close")
    public RestHighLevelClient client() {
        return new RestHighLevelClient(RestClient.builder(
                new HttpHost(host, port, "http")
        ));
    }
}
